package com.traffic.service.impl;

import com.ruoyi.common.security.utils.BaseUtil;
import com.traffic.domain.UserBasicinformation;
import com.traffic.mapper.UserBasicinformationMapper;
import com.traffic.service.IUserBasicinformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户基础信息Service业务层处理
 *
 * @author zzs
 * @date 2024-10-11
 */
@Service
public class UserBasicinformationServiceImpl implements IUserBasicinformationService
{
    @Autowired
    private UserBasicinformationMapper userBasicinformationMapper;

    /**
     * 查询用户基础信息
     *
     * @param userId 用户基础信息主键
     * @return 用户基础信息
     */
    @Override
    public UserBasicinformation selectUserBasicinformationByUserId(Long userId)
    {
        Long currentId = BaseUtil.getCurrentId();
        if(userId==-1){
            return userBasicinformationMapper.selectUserBasicinformationByUserId(currentId);
        }else {
            return userBasicinformationMapper.selectUserBasicinformationByUserId(userId);
        }
    }

    /**
     * 查询用户基础信息列表
     *
     * @param userBasicinformation 用户基础信息
     * @return 用户基础信息
     */
    @Override
    public List<UserBasicinformation> selectUserBasicinformationList(UserBasicinformation userBasicinformation)
    {
        return userBasicinformationMapper.selectUserBasicinformationList(userBasicinformation);
    }

    /**
     * 新增用户基础信息
     *
     * @param userBasicinformation 用户基础信息
     * @return 结果
     */
    @Override
    public int insertUserBasicinformation(UserBasicinformation userBasicinformation)
    {
        if (userBasicinformation.getUserId()==null){
            userBasicinformation.setUserId(BaseUtil.getCurrentId());
            return userBasicinformationMapper.insertUserBasicinformation(userBasicinformation);
        }
        return userBasicinformationMapper.updateUserBasicinformation(userBasicinformation);
    }

    /**
     * 修改用户基础信息
     *
     * @param userBasicinformation 用户基础信息
     * @return 结果
     */
    @Override
    public int updateUserBasicinformation(UserBasicinformation userBasicinformation)
    {

        return userBasicinformationMapper.updateUserBasicinformation(userBasicinformation);
    }

    /**
     * 批量删除用户基础信息
     *
     * @param userIds 需要删除的用户基础信息主键
     * @return 结果
     */
    @Override
    public int deleteUserBasicinformationByUserIds(Long[] userIds)
    {
        return userBasicinformationMapper.deleteUserBasicinformationByUserIds(userIds);
    }

    /**
     * 删除用户基础信息信息
     *
     * @param userId 用户基础信息主键
     * @return 结果
     */
    @Override
    public int deleteUserBasicinformationByUserId(Long userId)
    {
        return userBasicinformationMapper.deleteUserBasicinformationByUserId(userId);
    }
}
